package com.zuihai.app.mvp.ui.utils;

import com.blankj.utilcode.util.LogUtils;
import com.google.gson.Gson;
import com.zuihai.app.mvp.constant.UrlConstant;
import com.zuihai.app.mvp.model.api.my.IDelete;
import com.zuihai.app.mvp.model.entity.BaseMainClass;
import com.zuihai.app.mvp.ui.widget.MyToast;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Administrator on 2017/6/7 0007.
 */

public class RetrofitUtils {
    public static Retrofit getPost(){
        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

        OkHttpClient okHttpClient = new OkHttpClient.Builder()
                .addInterceptor(loggingInterceptor)
                .build();

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(UrlConstant.BASEURL)
                //增加返回值为Gson的支持(以实体类返回)
                .addConverterFactory(GsonConverterFactory.create())
                //增加返回值为Oservable<T>的支持
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .client(okHttpClient)
                .build();
       return retrofit;
    }

    public static Retrofit getPicutrePost(){
        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

        OkHttpClient okHttpClient = new OkHttpClient.Builder()
                .addInterceptor(loggingInterceptor)
                .build();

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(UrlConstant.BASEURL)
                //增加返回值为Gson的支持(以实体类返回)
                .addConverterFactory(GsonConverterFactory.create(new Gson()))
                //增加返回值为Oservable<T>的支持
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .client(okHttpClient)
                .build();
        return retrofit;
    }
    public static void requestDeleteRetrofit(int tag){
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(UrlConstant.BASEURL)
                //增加返回值为Gson的支持(以实体类返回)
                .addConverterFactory(GsonConverterFactory.create())
                //增加返回值为Oservable<T>的支持
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .build();
        IDelete delete=retrofit.create(IDelete.class);
        delete.deleteAllFootprint(UserDataUtils.getUserID(),tag)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseMainClass>() {
                    @Override
                    public void onCompleted() {
                        MyToast.showSuccess("成功删除全部的足迹");
                        //mFragments.get(0).
                    }

                    @Override
                    public void onError(Throwable e) {
                        LogUtils.e("成功了 complteted");
                    }

                    @Override
                    public void onNext(BaseMainClass baseMainClass) {
                        LogUtils.e(""+  baseMainClass.getData().toString());
                        LogUtils.e(""+    baseMainClass.getMsg().toString());


                    }


                });
    }
}
